using System.Collections.Generic;

namespace QueryBuilder.Core.Query
{
    /// <summary>
    /// 
    /// </summary>
    public class SqlQuery
    {
        /// <summary>
        /// 
        /// </summary>
        public List<Aggregate> aggrigates = new List<Aggregate>();

        /// <summary>
        /// 
        /// </summary>
        private List<ITable> fromTables = new List<ITable>();

        /// <summary>
        /// 
        /// </summary>
        private List<Column> groupBys = new List<Column>();

        /// <summary>
        /// 
        /// </summary>
        private List<Join> joins = new List<Join>();

        /// <summary>
        /// 
        /// </summary>
        private List<OrderBy> orderBys = new List<OrderBy>();

        /// <summary>
        /// 
        /// </summary>
        private QueryType queryType;

        /// <summary>
        /// 
        /// </summary>
        private List<Constraint> selectSource = new List<Constraint>();

        /// <summary>
        /// Gets or sets the constraint.
        /// </summary>
        /// <value>The constraint.</value>
        public Constraint Constraint { get; set; }

        /// <summary>
        /// Gets the order bys.
        /// </summary>
        /// <value>The order bys.</value>
        public IEnumerable<OrderBy> OrderBys
        {
            get { return this.orderBys; }
        }

        /// <summary>
        /// Gets the group bys.
        /// </summary>
        /// <value>The group bys.</value>
        public IEnumerable<Column> GroupBys
        {
            get { return this.groupBys; }
        }

        /// <summary>
        /// Gets the joins.
        /// </summary>
        /// <value>The joins.</value>
        public IEnumerable<Join> Joins
        {
            get { return this.joins; }
        }

        /// <summary>
        /// Gets from tables.
        /// </summary>
        /// <value>From tables.</value>
        public IEnumerable<ITable> FromTables
        {
            get { return this.fromTables; }
        }

        /// <summary>
        /// Gets the select source.
        /// </summary>
        /// <value>The select source.</value>
        public IEnumerable<Constraint> SelectSource
        {
            get { return this.selectSource; }
        }

        /// <summary>
        /// Gets the type of the query.
        /// </summary>
        /// <value>The type of the query.</value>
        public QueryType QueryType
        {
            get { return this.queryType; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is select all fields.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is select all fields; otherwise, <c>false</c>.
        /// </value>
        public bool IsSelectAllFields { get; set; }

        /// <summary>
        /// Adds from.
        /// </summary>
        /// <param name="table">The table.</param>
        public void AddFrom(ITable table)
        {
            this.fromTables.Add(table);
        }

        /// <summary>
        /// Adds the join.
        /// </summary>
        /// <param name="join">The join.</param>
        public void AddJoin(Join join)
        {
            this.joins.Add(join);
        }

        /// <summary>
        /// Adds the order by.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="orderByType">Type of the order by.</param>
        public void AddOrderBy(Column column, OrderByType orderByType)
        {
            var orderBy = new OrderBy(column, orderByType);
            this.orderBys.Add(orderBy);
        }

        /// <summary>
        /// Adds the select source.
        /// </summary>
        /// <param name="column">The column.</param>
        public void AddSelectSource(Constraint column)
        {
            this.selectSource.Add(column);
        }

        /// <summary>
        /// Adds the group by.
        /// </summary>
        /// <param name="column">The column.</param>
        public void AddGroupBy(Column column)
        {
            this.groupBys.Add(column);
        }
    }
}